-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[STEP2-4] Add Feature Blocking domains #113
base: sunsun512
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
step 2-2 맞나요? 2-4 같습니다.
public class UrlShortenService { | ||
|
||
private final BlackListService blackListService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service 간 호출이 이루어지고 있네요. service 레이어의 구분에 대해 고민해주세요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BlockedDomainInterface 으로 레이어를 구분했습니다.
src/main/java/community/whatever/onembackendjava/api/service/UrlShortenService.java
Outdated
Show resolved
Hide resolved
@@ -35,6 +38,9 @@ public ShortenUrlDto.Create.Response shortenUrlCreate(ShortenUrlDto.Create.Reque | |||
if (validateOriginUrl(param.getOriginUrl())) { | |||
throw BusinessExceptionGenerator.createBusinessException("DB001"); | |||
} | |||
if(isBlocked(param.getOriginUrl())){ | |||
throw BusinessExceptionGenerator.createBusinessException("DB004"); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 형식이라면 ErrorCode enum 을 매개변수로 받는게 낫지 않나요?
src/main/java/community/whatever/onembackendjava/common/util/BlackListService.java
Show resolved
Hide resolved
- BlockedDomain을 csvv 파일을 업로드 받아서 하는 것으로 변경 - BlockedDomain을 domain layer단으로 변경
…omain # Conflicts: # src/main/resources/application-dev.yml
log.info("file >> {}", file); | ||
csvReaderService.loadBlockedDomains(file); | ||
return ResponseFormatter.ConvertResponse(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POST /csv/upload
- 전 이게 무슨 기능인지 api endpoint 만 봐서는 전혀 유추되지 않습니다.
- admin 기능에 가까운데 누구나 사용할 수 있는 것 처럼 보입니다.
public interface BlockedDomainInterface { | ||
void loadBlockedDomains(MultipartFile file); // CSV 파일에서 차단 목록 로드 | ||
Set<String> getBlockedDomains(); // 차단된 도메인 목록 반환 | ||
boolean isBlocked(String url); // 특정 URL이 차단된 도메인인지 확인 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
전 모든 자료형을 wrapper 로 사용합니다.
import java.util.Set; | ||
|
||
public interface BlockedDomainInterface { | ||
void loadBlockedDomains(MultipartFile file); // CSV 파일에서 차단 목록 로드 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi. javadoc
public boolean isBlocked(String url) { | ||
for (String domain : blockedDomains) { | ||
if (url.contains(domain)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public boolean isBlocked(String url) {
return blockedDomains.stream().anyMatch(url::contains);
}
nit
String line; | ||
while ((line = br.readLine()) != null) { | ||
domainSet.add(line.trim()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blockedDomains.addAll(br.lines()
.map(String::trim)
.collect(Collectors.toSet()));
nit
@Service | ||
public class CsvReaderService implements BlockedDomainInterface { | ||
|
||
private Set<String> blockedDomains = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi. 일급 컬렉션, holder
변동사항